﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;

public partial class GetVerifyCode : System.Web.UI.Page
{
    static VerifyCodeDAO dao = new VerifyCodeDAO();
    static Base_EmployeeDAO employdao = new Base_EmployeeDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ResultEntity entity = new ResultEntity();
        entity.Name = "Verify";

        if (!string.IsNullOrEmpty(Request.QueryString["phone"]))
        {
            Base_Employee employ = employdao.GetInfo(" where phone = '" + Request.QueryString["phone"] + "'");

            if (employ != null)
            {
                VerifyCode code = new VerifyCode();
                code.CodeNum = new Random().Next(1000, 9999).ToString();
                code.CreateTime = DateTime.Now;
                code.RevPhone = Request.QueryString["phone"];
                code.RevUserName = "0";
                dao.InsertData(code);

                entity.ResultCode = "0";
                //entity.Contents = "{\"code\":\"" + code.CodeNum + "\",\"FromServices\":\"" + employ.FromServices + "\"}";
                entity.Contents = "{\"FromServices\":\"" + employ.FromServices + "\"}";

                entity.Desc = SendSMS.SendVerfyCode(code.CodeNum, Request.QueryString["phone"]);

                Response.Write(Common.ReturnResult(entity));

            }
            else
            {
                entity.ResultCode = "-1";
                entity.Desc = "账号不存在！";
                Response.Write(Common.ReturnResult(entity));
            }
        }
        else
        {
            entity.ResultCode = "-2";
            entity.Desc = "参数不正确！";
            Response.Write(Common.ReturnResult(entity));
        }
    }
}
